// 地点管理信息
import request from '@/utils/request1'

// 查询地点管理列表
export function locationList(query) {
  return request({
    url: '/logistics/location/list',
    method: 'get',
    params: query
  })
}
// 查询用途
export function getDictLocationUse() {
  return request({
    url: '/logistics/location/getDictLocationUse',
    method: 'get'
  })
}
// 查询类型
export function getDictLocationType() {
  return request({
    url: '/logistics/location/getDictLocationType',
    method: 'get'
  })
}
// 新增地点管理
export function addLocation(data) {
  return request({
    url: '/logistics/location',
    method: 'post',
    data: data
  })
}
//   修改地点管理
export function updateLocation(data) {
  return request({
    url: '/logistics/location',
    method: 'put',
    data: data
  })
}
//   批量覆盖用途
export function batchUpdateUseTo(query) {
  return request({
    url: '/logistics/location/batchUpdateUseTo',
    method: 'put',
    params: query,
    paramsSerializer: (params) => {
      return Object.keys(params)
        .map((key) => {
          if (Array.isArray(params[key])) {
            // 将数组元素转换为 idList=... 的形式
            return params[key].map((value) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`).join('&')
          }
          return `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`
        })
        .join('&')
    }
  })
}
//   批量增加用途
export function batchAddUseTo(query) {
  return request({
    url: '/logistics/location/batchAddUseTo',
    method: 'put',
    params: query,
    paramsSerializer: (params) => {
      return Object.keys(params)
        .map((key) => {
          if (Array.isArray(params[key])) {
            // 将数组元素转换为 idList=... 的形式
            return params[key].map((value) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`).join('&')
          }
          return `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`
        })
        .join('&')
    }
  })
}
//   批量修改状态
export function batchUpdateStatus(query) {
  return request({
    url: '/logistics/location/batchUpdateStatus',
    method: 'put',
    params: query,
    paramsSerializer: (params) => {
      return Object.keys(params)
        .map((key) => {
          if (Array.isArray(params[key])) {
            // 将数组元素转换为 idList=... 的形式
            return params[key].map((value) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`).join('&')
          }
          return `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`
        })
        .join('&')
    }
  })
}
// 删除
export function delLocation(ids) {
  return request({
    url: '/logistics/location/' + ids,
    method: 'delete'
  })
}
// 删除帮助中心关联文件
export function deleteFileIds(ids) {
  return request({
    url: '/logistics/helpCenter/deleteFileIds/' + ids,
    method: 'delete'
  })
}
//   获取详细信息
export function getlocationDetail(roleId) {
  return request({
    url: '/logistics/location/' + roleId,
    method: 'get'
  })
}
// 导入
export function importData(data) {
  return request({
    url: '/logistics/location/importData',
    method: 'post',
    data
  })
}
const obj = {
  locationList,
  getDictLocationUse,
  getDictLocationType,
  addLocation,
  getlocationDetail,
  updateLocation,
  batchUpdateUseTo,
  batchAddUseTo,
  batchUpdateStatus,
  delLocation,
  deleteFileIds,
  importData
}
export default obj
